
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<error.h>

int main()
{
    printf("main pid:%d\n",getpid());
    pid_t id = fork();
    if(id < 0)
    {
        //失败
        perror("fork:");
    }
    else if (id == 0)
    {
        //子进程
        while(1)
        {
            printf("\n child  pid:%d  ,ppid:%d  \n",getpid(), getppid());
            sleep(1);
        }
    }
    else
    {
        //剩下就是父进程
        while(1)
        {
            printf("\n parent  pid:%d  ,ppid:%d  \n",getpid(), getppid());
            sleep(1);
        }
    }
    return 0;
}
